var prefix = ctx + "manage/adRecord";
var prefixAdRecord = ctx + "manage/adRecord";
var prefixUserDailyActivity = ctx + "manage/userDailyActivity";
var prefixSecondary = ctx + "manage/adRecordSecondary";

$(function () {
    var options = {
        url: prefix + "/rankList",
        queryParams: queryParams,
        columns: [
            {
                field: 'index',
                title: '排行'
            },
            {
                field: 'id',
                title: '用户ID'
            },
            {
                field: 'adCount',
                title: '总次数'
            },
            {
                field: 'adCountMoney',
                title: '总金币',
                formatter: function (value, row, index) {
                    var valueResult = (value / 10000);
                    return value + '<span class="text-danger">≈' + valueResult + '元</span>';
                }
            },
            {
                field: 'count',
                title: '广告次数'
            },
            {
                field: 'money',
                title: '广告金币',
                formatter: function (value, row, index) {
                    var valueResult = (value / 10000);
                    return value + '<span class="text-danger">≈' + valueResult + '元</span>';
                }
            },
            {
                field: 'secondaryCount',
                title: '副广次数'
            },
            {
                field: 'secondaryMoney',
                title: '副广金币',
                formatter: function (value, row, index) {
                    var valueResult = (value / 10000);
                    return value + '<span class="text-danger">≈' + valueResult + '元</span>';
                }
            },
            {
                field: 'parenId',
                title: '代理ID',
                formatter: function (value, row, index) {
                    if (row.parenId && indexRow !== 2) {
                        return '<a href="#" onclick="getParenId(\'' + row.parenId + '\')">' + value + '</a>';
                    }
                    return "-";
                }
            },
            {
                title: '主广记录',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryAdRecord(\'' + row.id + '\')"><i>详细</i></a> ');
                    return actions.join('');
                }
            },
            {
                title: '副广记录',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryAdRecordSecondary(\'' + row.id + '\')"><i>详细</i></a> ');
                    return actions.join('');
                }
            },
            {
                title: '设备环境',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryUserDaily(\'' + row.id + '\')"><i>详细</i></a> ');
                    return actions.join('');
                }
            }
        ]
    };
    $.ryTable.initData(options);
});

/*奖励记录-搜索*/
function search() {
    $('.bootstrap-table').bootstrapTable('refresh', queryParams);
}

function queryParams(params) {
    var createTime = $('#createTime').val();
    if (!createTime) {
        $.modalAlert("请选择时间", modal_status.FAIL);
        return;
    }
    var startCreatTime = createTime + " 00:00:00";
    var endTime = createTime + " 23:59:59";
    return {
        // 传递参数查询参数
        pageSize: 100000,
        arChannel: $("#arChannel option:selected").val(),
        uvChannel: $("#uvChannel option:selected").val(),
        index: index,
        startTime: createTime === '' ? '' : startCreatTime,
        endTime: createTime === '' ? '' : endTime
    };
}

function exportExcel() {
    var createTime = $('#createTime').val();
    var startCreatTime = createTime + " 00:00:00";
    var endTime = createTime + " 23:59:59";
    startCreatTime = createTime === '' ? '' : startCreatTime;
    endTime = createTime === '' ? '' : endTime;
    var url = prefix + "/excel?arChannel=" + $("#arChannel option:selected").val() + "&startTime=" + startCreatTime + "&endTime=" + endTime + "&uvChannel=" + $("#uvChannel option:selected").val() + "&index=" + index;
    window.location.href = url;
}

function queryAdRecord(id) {
    var url = prefixAdRecord + '/' + id;
    layer_showAuto("主广记录详细", url);
}

function queryAdRecordSecondary(id) {
    var url = prefixSecondary + '/' + id;
    layer_showAuto("副广记录详细", url);
}

function queryUserDaily(id) {
    var url = prefixUserDailyActivity + "/my/" + id;
    layer_showAuto("风控日志详细", url);
}

function getParenId(id) {
    var url = prefix + "/parentId/" + id + "," + index;
    layer_showAuto("代理排行详细【代理ID=" + id + "】", url);
}






